package com.ruoyi.ucar.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ucar.boreq.WithdrawRecordDetailQueryBoReq;
import com.ruoyi.ucar.boreq.WithdrawRecordListQueryBoReq;
import com.ruoyi.ucar.boresp.*;
import com.ruoyi.ucar.domain.po.WithdrawRecordDetailQueryPo;
import com.ruoyi.ucar.domain.po.WithdrawRecordListQueryPo;
import com.ruoyi.ucar.mapper.TWithdrawRecordMapper;
import com.ruoyi.ucar.moreq.WithdrawRecordDetailQueryMoReq;
import com.ruoyi.ucar.moreq.WithdrawRecordListQueryMoReq;
import com.ruoyi.ucar.service.ITWithdrawRecordService;
import com.ruoyi.ucar.domain.TWithdrawRecord;
import com.ruoyi.ucar.util.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 提现记录Service业务层处理
 * 
 * @author sungangbin
 * @date 2025-05-13
 */
@Service
public class TWithdrawRecordServiceImpl extends ServiceImpl<TWithdrawRecordMapper, TWithdrawRecord> implements ITWithdrawRecordService
{
    @Autowired
    private TWithdrawRecordMapper tWithdrawRecordMapper;

    /**
     * 查询提现记录
     * 
     * @param id 提现记录主键
     * @return 提现记录
     */
    @Override
    public TWithdrawRecord selectTWithdrawRecordById(Long id)
    {
        return tWithdrawRecordMapper.selectTWithdrawRecordById(id);
    }

    /**
     * 查询提现记录列表
     * 
     * @param tWithdrawRecord 提现记录
     * @return 提现记录
     */
    @Override
    public List<TWithdrawRecord> selectTWithdrawRecordList(TWithdrawRecord tWithdrawRecord)
    {
        return tWithdrawRecordMapper.selectTWithdrawRecordList(tWithdrawRecord);
    }

    /**
     * 新增提现记录
     * 
     * @param tWithdrawRecord 提现记录
     * @return 结果
     */
    @Override
    public int insertTWithdrawRecord(TWithdrawRecord tWithdrawRecord)
    {
        return tWithdrawRecordMapper.insertTWithdrawRecord(tWithdrawRecord);
    }

    /**
     * 修改提现记录
     * 
     * @param tWithdrawRecord 提现记录
     * @return 结果
     */
    @Override
    public int updateTWithdrawRecord(TWithdrawRecord tWithdrawRecord)
    {
        return tWithdrawRecordMapper.updateTWithdrawRecord(tWithdrawRecord);
    }

    /**
     * 批量删除提现记录
     * 
     * @param ids 需要删除的提现记录主键
     * @return 结果
     */
    @Override
    public int deleteTWithdrawRecordByIds(Long[] ids)
    {
        return tWithdrawRecordMapper.deleteTWithdrawRecordByIds(ids);
    }

    /**
     * 删除提现记录信息
     * 
     * @param id 提现记录主键
     * @return 结果
     */
    @Override
    public int deleteTWithdrawRecordById(Long id)
    {
        return tWithdrawRecordMapper.deleteTWithdrawRecordById(id);
    }
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public WithdrawRecordListQueryBoResp queryWithdrawRecordList(WithdrawRecordListQueryBoReq withdrawRecordListQueryBoReq) {
        WithdrawRecordListQueryBoResp withdrawRecordListQueryBoResp = new WithdrawRecordListQueryBoResp();
        Page<WithdrawRecordListQueryPo> page=new Page<>(withdrawRecordListQueryBoReq.getPageIndex(),withdrawRecordListQueryBoReq.getPageSize());
        WithdrawRecordListQueryMoReq withdrawRecordListQueryMoReq= new WithdrawRecordListQueryMoReq();
        withdrawRecordListQueryMoReq.setDeleteFlag(1l);
        IPage<WithdrawRecordListQueryPo> withdrawRecordListQueryPage= tWithdrawRecordMapper.withdrawRecordListQueryPage(page,withdrawRecordListQueryMoReq);
        if(StringUtils.isNotNull(withdrawRecordListQueryPage.getRecords())&&withdrawRecordListQueryPage.getRecords().size()>0){
            withdrawRecordListQueryBoResp.setTotalCount(new Integer(String.valueOf(withdrawRecordListQueryPage.getTotal())));
            withdrawRecordListQueryBoResp.setTotalPage(new Integer(String.valueOf(withdrawRecordListQueryPage.getPages())));
            List<WithdrawRecordListQueryBo>  withdrawRecordListQueryBos=new ArrayList<>();
            withdrawRecordListQueryPage.getRecords().forEach(withdrawRecordListQueryPo -> {
                WithdrawRecordListQueryBo withdrawRecordListQueryBo= CommonUtil.objToObj(withdrawRecordListQueryPo,WithdrawRecordListQueryBo.class);
                withdrawRecordListQueryBo.setWithdrawWayDict(DictUtils.getDictLabel("withdraw_way",withdrawRecordListQueryPo.getWithdrawWay()));
                withdrawRecordListQueryBo.setWithdrawStatusDict(DictUtils.getDictLabel("recharge_status",withdrawRecordListQueryPo.getWithdrawStatus()));
                withdrawRecordListQueryBos.add(withdrawRecordListQueryBo);
            });
            withdrawRecordListQueryBoResp.setWithdrawRecordListQueryBos(withdrawRecordListQueryBos);
            logger.info("提现记录查询BO端返回结果：{}"+withdrawRecordListQueryBoResp);
        }else{
            return null;
        }
        return withdrawRecordListQueryBoResp;
    }

    @Override
    public WithdrawRecordDetailQueryBoResp withdrawRecordDetail(WithdrawRecordDetailQueryBoReq withdrawRecordDetailQueryBoReq) {
        WithdrawRecordDetailQueryMoReq withdrawRecordDetailQueryMoReq=CommonUtil.objToObj(withdrawRecordDetailQueryBoReq, WithdrawRecordDetailQueryMoReq.class)  ;
        withdrawRecordDetailQueryMoReq.setDeleteFlag(1l);
        List<WithdrawRecordDetailQueryPo> withdrawRecordDetailQueryPos=tWithdrawRecordMapper.withdrawRecordDetailQuery(withdrawRecordDetailQueryMoReq);
        if(StringUtils.isNotNull(withdrawRecordDetailQueryPos)&&withdrawRecordDetailQueryPos.size()>0){
            WithdrawRecordDetailQueryPo withdrawRecordDetailQueryPo=withdrawRecordDetailQueryPos.get(0);
            WithdrawRecordDetailQueryBoResp withdrawRecordDetailQueryBoResp=CommonUtil.objToObj(withdrawRecordDetailQueryPo,WithdrawRecordDetailQueryBoResp.class);
            withdrawRecordDetailQueryBoResp.setWithdrawWayDict(DictUtils.getDictLabel("withdraw_way",withdrawRecordDetailQueryPo.getWithdrawWay()));
            withdrawRecordDetailQueryBoResp.setWithdrawStatusDict(DictUtils.getDictLabel("recharge_status",withdrawRecordDetailQueryPo.getWithdrawStatus()));

            return withdrawRecordDetailQueryBoResp;
        }else{
            return null;
        }
    }
}
